import { defineStore } from 'pinia'
//vue.use 使用的

// 定义store的id
const useUserStore = defineStore('user', {
    // 定义store的状态
    state: () => ({
        name: '',
        email: '',
        userId: false,

        //0表示未登录
        isLogin:0,
    }),
    // 定义store的getters 同步
    getters: {
        getUserId: (val) => {return this.data.userId},
        setUserId:(val)=>{
            this.data.userId=val;
        },
        setIsLogin:(val)=>{this.data.isLogin=val},
        getIsLogin:(val)=>{return this.data.isLogin}
    },
    // 定义store的actions  异步
    actions: {
        login(name, email) {
            this.name = name
            this.email = email
            this.loggedIn = true
        },
        logout() {
            this.name = ''
            this.email = ''
            this.loggedIn = false
        }
    }
})

export default {useUserStore}